<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopCommissionAgentTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_commission_agent', ['comment' => '分销商', 'engine' => 'InnoDB', 'id' => false, 'primary_key' => 'user_id', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('user_id', 'integer', ['limit'  =>  11, 'null' => false, 'default' => 0, 'comment' => '用户'])
            ->addColumn('level', 'integer', ['limit'  =>  11, 'comment' => '分销商等级'])
            ->addColumn('apply_info', 'text', ['null' => true, 'comment' => '申请信息'])
            ->addColumn('total_income', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '总收益'])
            ->addColumn('child_order_money_0', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '自购/直推分销订单金额'])
            ->addColumn('child_order_money_1', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '一级分销订单总金额'])
            ->addColumn('child_order_money_2', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '二级分销订单总金额'])
            ->addColumn('child_order_money_all', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '团队分销订单总金额'])
            ->addColumn('child_order_count_0', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '自购/直推分销订单数量'])
            ->addColumn('child_order_count_1', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '一级分销订单数量'])
            ->addColumn('child_order_count_2', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '二级分销订单数量'])
            ->addColumn('child_order_count_all', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '团队分销订单数量'])
            ->addColumn('child_agent_count_1', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '直推分销商人数'])
            ->addColumn('child_agent_count_2', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '二级分销商人数'])
            ->addColumn('child_agent_count_all', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '团队分销商人数'])
            ->addColumn('child_agent_level_1', 'string', ['limit' => 255, 'null' => true, 'default' => '', 'comment' => '一级分销商等级统计'])
            ->addColumn('child_agent_level_all', 'string', ['limit' => 255, 'null' => true, 'default' => '', 'comment' => '团队分销商等级统计'])
            ->addColumn('child_user_count_1', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '一级用户人数'])
            ->addColumn('child_user_count_2', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '二级用户人数'])
            ->addColumn('child_user_count_all', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '团队用户人数'])
            ->addColumn(Column::tinyInteger('upgrade_lock')->setDefault(0)->setComment('升级锁定:0=不锁定,1=锁定'))
            ->addColumn('apply_num', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '提交申请次数'])
            ->addColumn(Column::tinyInteger('level_status')->setDefault(0)->setComment('升级状态:0=不升级,>1=待升级等级'))
            ->addColumn('status', 'string', ['limit' => 20, 'default' => 'normal', 'comment' => '分销商状态:forbidden=禁用,pending=审核中,freeze=冻结,normal=正常,reject=拒绝'])
            ->addColumn('become_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '成为分销商时间'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_commission_agent');
        $table->drop();
    }
}
